<?php 

	error_reporting(0);
	session_start();
	error_reporting(1);
	
	require_once "../common/PinSQL.obj";
	$pinSQL = new PinSQL();
	
	global $site_root;
	global $showUser;

	if ($showUser)
	{
		$viewingUser = $showUser;
		$pinSQL->Query("SELECT * FROM buzz WHERE touser='$viewingUser' ORDER BY date DESC");
		$totalposts = $pinSQL->GetNumRows();
		if ($totalposts > 5)
		{
			$pinSQL->Query("SELECT * FROM buzz WHERE touser='$viewingUser' ORDER BY date DESC LIMIT 0, 5");	
			$truncated = TRUE;
?>
Showing 5 of <?php echo $totalposts; ?> buzz posts.
<br /><img src="/img/arrow_blue.gif" /><a href="frame.php?page=profile&tab=buzz&user=<?php echo $viewingUser; ?>">View all</a>
<?php
		} else {
?>
Showing all <?php echo $totalposts; ?> buzz posts.
<?php
		}
	} else {
		$viewingUser = $username;
		$pinSQL->Query("SELECT * FROM buzz WHERE touser='$viewingUser' ORDER BY date DESC");
	}
	
	if ( $pinSQL->GetNumRows() )
	{
		while ( $row = $pinSQL->FetchNextRow() )
		{
			$fromuser = $row['fromuser'];
			$date = $row['date'];
			$message = $row['message'];
			$id = $row['id'];
			
			$firstname = $pinSQL->GetUserField($fromuser, "firstname");
			
			$prettydate = date('F j, Y', strtotime($date));
			$prettytime = date('g:ia', strtotime($date));
				
?>

<?php include "../browser_detect.php"; ?>
				
       <div class="horizontal_separation"></div>
       <div class="comments_header">
       
<?php
		$picurl = $pinSQL->GetUserdataField($fromuser, "picurl");
		if ($picurl)
		{
			$imageSize = getimagesize("userData/$fromuser/$picurl");
			
			if ($imageSize[1] <= 30)
			{
				$newWidth = $imageSize[0];
				$newHeight = $imageSize[1];
			} else {
				$widthFactor = $imageSize[0] / $imageSize[1];
				$newHeight = 30;
				$newWidth = $newHeight * $widthFactor;
			}
?>
		<img src="/members/userData/<?php echo $fromuser . "/" . $picurl; ?>" width="<?php echo $newWidth; ?>" height="<?php echo $newHeight; ?>" />	
		<div style="position: absolute; left: <?php echo ($newWidth+10); ?>px; top: 0px;">
<?php
		}
?>
            <a href="/members/frame.php?page=profile&user=<?php echo $fromuser; ?>" target="_top"><?php echo ($firstname) ? $firstname : $fromuser; ?></a>
            <span class="paleheader_sm">wrote
			<br />at <?php echo "$prettytime on $prettydate"; ?></span>
<?php if ($picurl) { ?>		</div> <?php } ?>

       </div>
       
       <div class="horizontal_separation"></div>
       
       <div class="comment">
            <?php echo nl2br($message); ?>
       </div>
       
       <div class="comment_controls">
       <?php if (($_SESSION['username'] == $viewingUser) AND (!$showUser)) { ?>
            <a href="javascript:DeleteComment(<?php echo $id; ?>)">Delete</a> | 
       <?php } ?>
       <a href="frame.php?page=profile&tab=buzz&user=<?php echo $fromuser; ?>&write=1">
       <?php if ($_SESSION['username'] == $viewingUser) { ?>Reply<?php } else { ?>Buzz<?php } ?></a>
       </div>
       
       <?php if (!$ie6){ ?><div class="horizontal_separation"></div><?php } ?>
	       
<?php
		}
	}
	else
	{
?>
		<div class="important">No buzz</div>
			<?php echo $username; ?>'s buzz is currently empty.
		</div>
<?php
	}
	
	$pinSQL->Close();
?>

		